
"""
1. 使用requests库调用TPshop登录功能的相关接口，完成登录操作
2. 登录成功后获取‘我的订单’页面的数据
获取验证码：http://localhost/index.php?m=Home&c=User&a=verify
接口地址：
登录：http://localhost/index.php?m=Home&c=User&a=do_login
登录用户：（username: 13088888888, password: 123456, verify_code: 8888）
我的订单：http://localhost/Home/Order/order_list.html
"""

import requests

# 获取验证码(get)：http://localhost/index.php?m=Home&c=User&a=verify
response = requests.get("http://localhost/index.php?m=Home&c=User&a=verify")
print(response.cookies)
PHPSESSID = response.cookies.get("PHPSESSID")

# 登录(post)：http://localhost/index.php?m=Home&c=User&a=do_login
# 登录用户：（username: 13088888888, password: 123456, verify_code: 8888）
login_url = "http://localhost/index.php?m=Home&c=User&a=do_login"
login_data = {
    "username": "13488888888",
    "password": "123456",
    "verify_code": "8888"
}
login_cookies = {
    "PHPSESSID": PHPSESSID
}
response = requests.post(url=login_url, data=login_data, cookies=login_cookies)
response.encoding = "utf-8"
print(response.json())

# 我的订单(get),記得要加cookies：http://localhost/Home/Order/order_list.html
response = requests.get("http://localhost/Home/Order/order_list.html", cookies=login_cookies)
response.encoding = "utf-8"
print("=" * 100)
print(response.text)








